<!DOCTYPE html>
<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
  <meta name="description" content="刘清政">
  <meta name="keyword" content="hexo-theme">
  
    <link rel="shortcut icon" href="/css/images/logo.png">
  
  <title>
    
      db/Redis系列/01-Redis系列之-API的使用 | Justin-刘清政的博客
    
  </title>
  <link href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
  <link href="//cdnjs.cloudflare.com/ajax/libs/nprogress/0.2.0/nprogress.min.css" rel="stylesheet">
  <link href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/tomorrow.min.css" rel="stylesheet">
  
<link rel="stylesheet" href="/css/style.css">

  
    
<link rel="stylesheet" href="/css/plugins/gitment.css">

  
  <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/geopattern/1.2.3/js/geopattern.min.js"></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/nprogress/0.2.0/nprogress.min.js"></script>
  
    
<script src="/js/qrious.js"></script>

  
  
    
<script src="/js/gitment.js"></script>

  
  

  
<meta name="generator" content="Hexo 4.2.0"></head>
<div class="wechat-share">
  <img src="/css/images/logo.png" />
</div>

  <body>
    <header class="header fixed-header">
  <div class="header-container">
    <a class="home-link" href="/">
      <div class="logo"></div>
      <span>Justin-刘清政的博客</span>
    </a>
    <ul class="right-list">
      
        <li class="list-item">
          
            <a href="/" class="item-link">主页</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/tags/" class="item-link">标签</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/archives/" class="item-link">归档</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/about/" class="item-link">关于我</a>
          
        </li>
      
    </ul>
    <div class="menu">
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
    </div>
    <div class="menu-mask">
      <ul class="menu-list">
        
          <li class="menu-item">
            
              <a href="/" class="menu-link">主页</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/tags/" class="menu-link">标签</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/archives/" class="menu-link">归档</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/about/" class="menu-link">关于我</a>
            
          </li>
        
      </ul>
    </div>
  </div>
</header>

    <div id="article-banner">
  <h2>db/Redis系列/01-Redis系列之-API的使用</h2>



  <p class="post-date">2019-12-24</p>
    <!-- 不蒜子统计 -->
    <span id="busuanzi_container_page_pv" style='display:none' class="">
        <i class="icon-smile icon"></i> 阅读数：<span id="busuanzi_value_page_pv"></span>次
    </span>
  <div class="arrow-down">
    <a href="javascript:;"></a>
  </div>
</div>
<main class="app-body flex-box">
  <!-- Article START -->
  <article class="post-article">
    <section class="markdown-content"><h2 id="一-通用命令"><a href="#一-通用命令" class="headerlink" title="一 通用命令"></a>一 通用命令</h2><h3 id="1-1-通用命令"><a href="#1-1-通用命令" class="headerlink" title="1.1 通用命令"></a>1.1 通用命令</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">####1-keys </span></span><br><span class="line"><span class="comment">#打印出所有key</span></span><br><span class="line">keys * </span><br><span class="line"><span class="comment">#打印出所有以he开头的key</span></span><br><span class="line">keys he*</span><br><span class="line"><span class="comment">#打印出所有以he开头，第三个字母是h到l的范围</span></span><br><span class="line">keys he[h-l]</span><br><span class="line"><span class="comment">#三位长度，以he开头，？表示任意一位</span></span><br><span class="line">keys he？</span><br><span class="line"><span class="comment">#keys命令一般不在生产环境中使用，生产环境key很多，时间复杂度为o(n),用scan命令</span></span><br><span class="line"></span><br><span class="line"><span class="comment">####2-dbsize   计算key的总数</span></span><br><span class="line">dbsize <span class="comment">#redis内置了计数器，插入删除值该计数器会更改，所以可以在生产环境使用，时间复杂度是o(1)</span></span><br><span class="line"></span><br><span class="line"><span class="comment">###3-exists key 时间复杂度o(1)</span></span><br><span class="line"><span class="comment">#设置a</span></span><br><span class="line">set a b</span><br><span class="line"><span class="comment">#查看a是否存在</span></span><br><span class="line">exists a</span><br><span class="line">(integer) <span class="number">1</span></span><br><span class="line"><span class="comment">#存在返回1 不存在返回0</span></span><br><span class="line"><span class="comment">###4-del key  时间复杂度o(1)</span></span><br><span class="line">删除成功返回<span class="number">1</span>，key不存在返回<span class="number">0</span></span><br><span class="line"><span class="comment">###5-expire key seconds  时间复杂度o(1)</span></span><br><span class="line">expire name <span class="number">3</span> <span class="comment">#3s 过期</span></span><br><span class="line">ttl name  <span class="comment">#查看name还有多长时间过期</span></span><br><span class="line">persist name <span class="comment">#去掉name的过期时间</span></span><br><span class="line"><span class="comment">###6-type key  时间复杂度o(1)</span></span><br><span class="line">type name <span class="comment">#查看name类型，返回string</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">### 7 其他</span></span><br><span class="line">info命令：内存，cpu，主从相关</span><br><span class="line">client list  正在连接的会话</span><br><span class="line">client kill ip:端口</span><br><span class="line">dbsize  总共有多少个key</span><br><span class="line">flushall  清空所有</span><br><span class="line">flushdb  只清空当前库</span><br><span class="line">select 数字  选择某个库  总共<span class="number">16</span>个库</span><br><span class="line">monitor  记录操作日志，夯住</span><br></pre></td></tr></table></figure>

<h3 id="1-2-数据结构和内部编码"><a href="#1-2-数据结构和内部编码" class="headerlink" title="1.2 数据结构和内部编码"></a>1.2 数据结构和内部编码</h3><p><img src="https://tva1.sinaimg.cn/large/006tNbRwgy1ga7mt5tzjnj30q20pgn5n.jpg" alt="image-20191224110401405"></p>
<h3 id="1-3-单线程架构"><a href="#1-3-单线程架构" class="headerlink" title="1.3 单线程架构"></a>1.3 单线程架构</h3><h4 id="1-3-1-单线程架构，"><a href="#1-3-1-单线程架构，" class="headerlink" title="1.3.1 单线程架构，"></a>1.3.1 单线程架构，</h4><p>一个瞬间只会执行一条命令</p>
<p><img src="https://tva1.sinaimg.cn/large/006tNbRwgy1ga7mzj7rpoj30wu0egq5t.jpg" alt="image-20191224111010657"></p>
<h4 id="1-3-2-单线程为什么这么快"><a href="#1-3-2-单线程为什么这么快" class="headerlink" title="1.3.2 单线程为什么这么快"></a>1.3.2 单线程为什么这么快</h4><p>1 纯内存</p>
<p>2 非阻塞IO （epoll），自身实现了事件处理，不在网络io上浪费过多时间</p>
<p>3 避免线程间切换和竞态消耗</p>
<h4 id="1-3-3-注意"><a href="#1-3-3-注意" class="headerlink" title="1.3.3 注意"></a>1.3.3 注意</h4><p>1 一次只运行一条命令</p>
<p>2 拒绝长慢命令</p>
<p>​    -keys，flushall,flushdb,慢的lua脚本，mutil/exec，operate，big value</p>
<p>3 其实不是单线程（在做持久化是另外的线程）</p>
<p>​    -fysnc file descriptor</p>
<p>​    -close file descriptor</p>
<h2 id="二-字符串类型"><a href="#二-字符串类型" class="headerlink" title="二 字符串类型"></a>二 字符串类型</h2><h3 id="2-1-字符串键值结构"><a href="#2-1-字符串键值结构" class="headerlink" title="2.1 字符串键值结构"></a>2.1 字符串键值结构</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">key          value</span><br><span class="line">hello        world      可以很复杂，如json格式字符串</span><br><span class="line">counter      <span class="number">1</span>          数字类型</span><br><span class="line">bits         <span class="number">10101010</span>   二进制（位图）</span><br><span class="line"><span class="comment">#字符串value不能大于512m，一般建议100k以内</span></span><br><span class="line"><span class="comment">#用于缓存，计数器，分布式锁...</span></span><br></pre></td></tr></table></figure>

<h3 id="2-2-常用命令"><a href="#2-2-常用命令" class="headerlink" title="2.2 常用命令"></a>2.2 常用命令</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">###1---基本使用get，set，del</span></span><br><span class="line">get name       <span class="comment">#时间复杂度 o(1)</span></span><br><span class="line">set name lqz   <span class="comment">#时间复杂度 o(1)</span></span><br><span class="line"><span class="keyword">del</span> name       <span class="comment">#时间复杂度 o(1)</span></span><br><span class="line"><span class="comment">###2---其他使用incr,decr,incrby,decrby</span></span><br><span class="line">incr age  <span class="comment">#对age这个key的value值自增1</span></span><br><span class="line">decr age  <span class="comment">#对age这个key的value值自减1</span></span><br><span class="line">incrby age <span class="number">10</span>  <span class="comment">#对age这个key的value值增加10</span></span><br><span class="line">decrby age <span class="number">10</span>  <span class="comment">#对age这个key的value值减10</span></span><br><span class="line"><span class="comment">#统计网站访问量（单线程无竞争，天然适合做计数器）</span></span><br><span class="line"><span class="comment">#缓存mysql的信息（json格式）</span></span><br><span class="line"><span class="comment">#分布式id生成（多个机器同时并发着生成，不会重复）</span></span><br><span class="line"><span class="comment">###3---set，setnx，setxx</span></span><br><span class="line">set name lqz  <span class="comment">#不管key是否存在，都设置 </span></span><br><span class="line">setnx name lqz <span class="comment">#key不存在时才设置（新增操作）</span></span><br><span class="line">set name lqz nx <span class="comment">#同上</span></span><br><span class="line">set name lqz xx <span class="comment">#key存在，才设置（更新操作）</span></span><br><span class="line"><span class="comment">###4---mget mset</span></span><br><span class="line">mget key1 key2 key3     <span class="comment">#批量获取key1，key2.。。时间复杂度o(n)</span></span><br><span class="line">mset key1 value1 key2 value2 key3 value3    <span class="comment">#批量设置时间复杂度o(n)</span></span><br><span class="line"><span class="comment">#n次get和mget的区别</span></span><br><span class="line"><span class="comment">#n次get时间=n次命令时间+n次网络时间</span></span><br><span class="line"><span class="comment">#mget时间=1次网络时间+n次命令时间</span></span><br><span class="line"><span class="comment">###5---其他：getset，append，strlen</span></span><br><span class="line">getset name lqznb <span class="comment">#设置新值并返回旧值 时间复杂度o(1)</span></span><br><span class="line">append name <span class="number">666</span> <span class="comment">#将value追加到旧的value 时间复杂度o(1)</span></span><br><span class="line">strlen name  <span class="comment">#计算字符串长度(注意中文)  时间复杂度o(1)</span></span><br><span class="line"><span class="comment">###6---其他：incrybyfloat,getrange,setrange</span></span><br><span class="line">increbyfloat age <span class="number">3.5</span>  <span class="comment">#为age自增3.5，传负值表示自减 时间复杂度o(1)</span></span><br><span class="line">getrange key start end <span class="comment">#获取字符串制定下标所有的值  时间复杂度o(1)</span></span><br><span class="line">setrange key index value <span class="comment">#从指定index开始设置value值  时间复杂度o(1)</span></span><br></pre></td></tr></table></figure>



<h2 id="三-哈希类型"><a href="#三-哈希类型" class="headerlink" title="三 哈希类型"></a>三 哈希类型</h2><p>###3.1 哈希值结构</p>
<p><img src="https://tva1.sinaimg.cn/large/006tNbRwgy1ga7otagi3lj30p00f2q8l.jpg" alt="image-20191224121323414"></p>
<h3 id="3-2-重要api"><a href="#3-2-重要api" class="headerlink" title="3.2 重要api"></a>3.2 重要api</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">###1---hget,hset,hdel</span></span><br><span class="line">hget key field  <span class="comment">#获取hash key对应的field的value 时间复杂度为 o(1)</span></span><br><span class="line">hset key field value <span class="comment">#设置hash key对应的field的value值 时间复杂度为 o(1)</span></span><br><span class="line">hdel key field <span class="comment">#删除hash key对应的field的值 时间复杂度为 o(1)</span></span><br><span class="line"><span class="comment">#测试</span></span><br><span class="line">hset user:<span class="number">1</span>:info age <span class="number">23</span></span><br><span class="line">hget user:<span class="number">1</span>:info ag</span><br><span class="line">hset user:<span class="number">1</span>:info name lqz</span><br><span class="line">hgetall user:<span class="number">1</span>:info</span><br><span class="line">hdel user:<span class="number">1</span>:info age</span><br><span class="line"><span class="comment">###2---hexists,hlen</span></span><br><span class="line">hexists key field  <span class="comment">#判断hash key 是否存在field 时间复杂度为 o(1)</span></span><br><span class="line">hlen key   <span class="comment">#获取hash key field的数量  时间复杂度为 o(1)</span></span><br><span class="line">hexists user:<span class="number">1</span>:info name</span><br><span class="line">hlen user:<span class="number">1</span>:info  <span class="comment">#返回数量</span></span><br><span class="line">        </span><br><span class="line"><span class="comment">###3---hmget，hmset</span></span><br><span class="line">hmget key field1 field2 ...fieldN  <span class="comment">#批量获取hash key 的一批field对应的值  时间复杂度是o(n)</span></span><br><span class="line">hmset key field1 value1 field2 value2  <span class="comment">#批量设置hash key的一批field value 时间复杂度是o(n)</span></span><br><span class="line"></span><br><span class="line"><span class="comment">###4--hgetall,hvals，hkeys</span></span><br><span class="line">hgetall key  <span class="comment">#返回hash key 对应的所有field和value  时间复杂度是o(n)</span></span><br><span class="line">hvals key   <span class="comment">#返回hash key 对应的所有field的value  时间复杂度是o(n)</span></span><br><span class="line">hkeys key   <span class="comment">#返回hash key对应的所有field  时间复杂度是o(n)</span></span><br><span class="line"><span class="comment">###小心使用hgetall</span></span><br><span class="line"><span class="comment">##1 计算网站每个用户主页的访问量</span></span><br><span class="line">hincrby user:<span class="number">1</span>:info pageview count</span><br><span class="line"><span class="comment">##2 缓存mysql的信息，直接设置hash格式</span></span><br></pre></td></tr></table></figure>



<h3 id="3-3-hash-vs-string"><a href="#3-3-hash-vs-string" class="headerlink" title="3.3 hash vs string"></a>3.3 hash vs string</h3><h4 id="3-3-1相似的api"><a href="#3-3-1相似的api" class="headerlink" title="3.3.1相似的api"></a>3.3.1相似的api</h4><table>
<thead>
<tr>
<th>get</th>
<th>hget</th>
</tr>
</thead>
<tbody><tr>
<td>set /sentnx</td>
<td>hset  hsetnx</td>
</tr>
<tr>
<td>del</td>
<td>hdel</td>
</tr>
<tr>
<td>incr incrby dear decrby</td>
<td>hincrby</td>
</tr>
<tr>
<td>mset</td>
<td>hmset</td>
</tr>
<tr>
<td>mget</td>
<td>hmget</td>
</tr>
</tbody></table>
<h4 id="3-3-2-缓存三种方案"><a href="#3-3-2-缓存三种方案" class="headerlink" title="3.3.2 缓存三种方案"></a>3.3.2 缓存三种方案</h4><p>直接json格式字符串</p>
<p>每个字段一个key</p>
<p>使用hash操作</p>
<h3 id="3-4-其他操作"><a href="#3-4-其他操作" class="headerlink" title="3.4 其他操作"></a>3.4 其他操作</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">##其他操作 hsetnx，hincrby，hincrbyfloat</span></span><br><span class="line">hsetnx key field value <span class="comment">#设置hash key对应field的value（如果field已存在，则失败），时间复杂度o(1)</span></span><br><span class="line">hincrby key field intCounter <span class="comment">#hash key 对英的field的value自增intCounter 时间复杂度o(1)</span></span><br><span class="line">hincrbyfloat key field floatCounter <span class="comment">#hincrby 浮点数 时间复杂度o(1)</span></span><br></pre></td></tr></table></figure>

<h2 id="四-列表类型"><a href="#四-列表类型" class="headerlink" title="四 列表类型"></a>四 列表类型</h2><h3 id="4-1-列表特点"><a href="#4-1-列表特点" class="headerlink" title="4.1 列表特点"></a>4.1 列表特点</h3><p>有序队列，可以从左侧添加，右侧添加，可以重复，可以从左右两边弹出</p>
<h4 id="4-2-API操作"><a href="#4-2-API操作" class="headerlink" title="4.2 API操作"></a>4.2 API操作</h4><h5 id="4-2-1-插入操作"><a href="#4-2-1-插入操作" class="headerlink" title="4.2.1 插入操作"></a>4.2.1 插入操作</h5><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#rpush 从右侧插入</span></span><br><span class="line">rpush key value1 value2 ...valueN  <span class="comment">#时间复杂度为o(1~n)</span></span><br><span class="line"><span class="comment">#lpush 从左侧插入</span></span><br><span class="line"><span class="comment">#linsert</span></span><br><span class="line">linsert key before|after value newValue   <span class="comment">#从元素value的前或后插入newValue 时间复杂度o(n) ，需要遍历列表</span></span><br><span class="line">linsert listkey before b java</span><br><span class="line">linsert listkey after b php</span><br></pre></td></tr></table></figure>

<h5 id="4-2-2-删除操作"><a href="#4-2-2-删除操作" class="headerlink" title="4.2.2 删除操作"></a>4.2.2 删除操作</h5><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">lpop key <span class="comment">#从列表左侧弹出一个item 时间复杂度o(1)</span></span><br><span class="line"></span><br><span class="line">rpop key <span class="comment">#从列表右侧弹出一个item 时间复杂度o(1)</span></span><br><span class="line"></span><br><span class="line">lrem key count value</span><br><span class="line"><span class="comment">#根据count值，从列表中删除所有value相同的项 时间复杂度o(n)</span></span><br><span class="line"><span class="number">1</span> count&gt;<span class="number">0</span> 从左到右，删除最多count个value相等的项</span><br><span class="line"><span class="number">2</span> count&lt;<span class="number">0</span> 从右向左，删除最多 Math.abs(count)个value相等的项</span><br><span class="line"><span class="number">3</span> count=<span class="number">0</span> 删除所有value相等的项</span><br><span class="line">lrem listkey <span class="number">0</span> a <span class="comment">#删除列表中所有值a</span></span><br><span class="line">lrem listkey <span class="number">-1</span> c <span class="comment">#从右侧删除1个c</span></span><br><span class="line"></span><br><span class="line">ltrim key start end <span class="comment">#按照索引范围修剪列表 o(n)</span></span><br><span class="line">ltrim listkey <span class="number">1</span> <span class="number">4</span> <span class="comment">#只保留下表1--4的元素</span></span><br></pre></td></tr></table></figure>

<h4 id="4-2-3-查询操作"><a href="#4-2-3-查询操作" class="headerlink" title="4.2.3 查询操作"></a>4.2.3 查询操作</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">lrange key start end <span class="comment">#包含end获取列表指定索引范围所有item  o(n)</span></span><br><span class="line">lrange listkey <span class="number">0</span> <span class="number">2</span></span><br><span class="line">lrange listkey <span class="number">1</span> <span class="number">-1</span> <span class="comment">#获取第一个位置到倒数第一个位置的元素</span></span><br><span class="line"></span><br><span class="line">lindex key index <span class="comment">#获取列表指定索引的item  o(n)</span></span><br><span class="line">lindex listkey <span class="number">0</span></span><br><span class="line">lindex listkey <span class="number">-1</span></span><br><span class="line"></span><br><span class="line">llen key <span class="comment">#获取列表长度</span></span><br></pre></td></tr></table></figure>

<h4 id="4-2-3-修改操作"><a href="#4-2-3-修改操作" class="headerlink" title="4.2.3 修改操作"></a>4.2.3 修改操作</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">lset key index newValue <span class="comment">#设置列表指定索引值为newValue o(n)</span></span><br><span class="line">lset listkey <span class="number">2</span> ppp <span class="comment">#把第二个位置设为ppp</span></span><br></pre></td></tr></table></figure>



<h3 id="4-3-实战"><a href="#4-3-实战" class="headerlink" title="4.3 实战"></a>4.3 实战</h3><p>实现timeLine功能，时间轴，微博关注的人，按时间轴排列，在列表中放入关注人的微博的即可</p>
<h3 id="4-4-其他操作"><a href="#4-4-其他操作" class="headerlink" title="4.4 其他操作"></a>4.4 其他操作</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">blpop key timeout <span class="comment">#lpop的阻塞版，timeout是阻塞超时时间，timeout=0为拥有不阻塞 o(1)</span></span><br><span class="line">brpop key timeout <span class="comment">#rpop的阻塞版，timeout是阻塞超时时间，timeout=0为拥有不阻塞 o(1)</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#要实现栈的功能</span></span><br><span class="line">lpush+lpop</span><br><span class="line"><span class="comment">#实现队列功能</span></span><br><span class="line">lpush+rpop</span><br><span class="line"><span class="comment">#固定大小的列表</span></span><br><span class="line">lpush+ltrim</span><br><span class="line"><span class="comment">#消息队列</span></span><br><span class="line">lpush+brpop</span><br></pre></td></tr></table></figure>

<h2 id="五-集合类型"><a href="#五-集合类型" class="headerlink" title="五 集合类型"></a>五 集合类型</h2><h3 id="5-1-特点"><a href="#5-1-特点" class="headerlink" title="5.1 特点"></a>5.1 特点</h3><p>无序，无重复，集合间操作（交叉并补） </p>
<h3 id="5-2-API操作"><a href="#5-2-API操作" class="headerlink" title="5.2 API操作"></a>5.2 API操作</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">sadd key element <span class="comment">#向集合key添加element（如果element存在，添加失败） o(1)</span></span><br><span class="line"></span><br><span class="line">srem key element <span class="comment">#从集合中的element移除掉 o(1)</span></span><br><span class="line"></span><br><span class="line">scard key <span class="comment">#计算集合大小</span></span><br><span class="line"></span><br><span class="line">sismember key element <span class="comment">#判断element是否在集合中</span></span><br><span class="line"></span><br><span class="line">srandmember key count <span class="comment">#从集合中随机取出count个元素，不会破坏集合中的元素</span></span><br><span class="line"></span><br><span class="line">spop key <span class="comment">#从集合中随机弹出一个元素</span></span><br><span class="line"></span><br><span class="line">smembers key <span class="comment">#获取集合中所有元素 ，无序，小心使用，会阻塞住 </span></span><br><span class="line"></span><br><span class="line">sdiff user:<span class="number">1</span>:follow user:<span class="number">2</span>:follow  <span class="comment">#计算user:1:follow和user:2:follow的差集</span></span><br><span class="line"></span><br><span class="line">sinter user:<span class="number">1</span>:follow user:<span class="number">2</span>:follow  <span class="comment">#计算user:1:follow和user:2:follow的交集</span></span><br><span class="line">          </span><br><span class="line">sunion user:<span class="number">1</span>:follow user:<span class="number">2</span>:follow  <span class="comment">#计算user:1:follow和user:2:follow的并集</span></span><br><span class="line">                </span><br><span class="line">sdiff|sinter|suion + store destkey... <span class="comment">#将差集，交集，并集结果保存在destkey集合中</span></span><br></pre></td></tr></table></figure>

<h3 id="5-3-实战"><a href="#5-3-实战" class="headerlink" title="5.3 实战"></a>5.3 实战</h3><p>抽奖系统 ：通过spop来弹出用户的id，活动取消，直接删除</p>
<p>点赞，点踩，喜欢等，用户如果点了赞，就把用户id放到该条记录的集合中</p>
<p>标签：给用户/文章等添加标签，sadd user:1:tags 标签1 标签2 标签3</p>
<p>给标签添加用户，关注该标签的人有哪些</p>
<p>共同好友：集合间的操作</p>
<h4 id="5-4-总结"><a href="#5-4-总结" class="headerlink" title="5.4 总结"></a>5.4 总结</h4><p>sadd:可以做标签相关</p>
<p>spop/srandmember:可以做随机数相关</p>
<p>sadd/sinter：社交相关</p>
<h2 id="六-有序集合类型"><a href="#六-有序集合类型" class="headerlink" title="六 有序集合类型"></a>六 有序集合类型</h2><h3 id="6-1-特点"><a href="#6-1-特点" class="headerlink" title="6.1 特点"></a>6.1 特点</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#有一个分值字段，来保证顺序</span></span><br><span class="line">key                  score                value</span><br><span class="line">user:ranking           <span class="number">1</span>                   lqz</span><br><span class="line">user:ranking           <span class="number">99</span>                  lqz2</span><br><span class="line">user:ranking           <span class="number">88</span>                  lqz3</span><br><span class="line"><span class="comment">#集合有序集合</span></span><br><span class="line">集合：无重复元素，无序，element</span><br><span class="line">有序集合：无重复元素，有序，element+score</span><br><span class="line"><span class="comment">#列表和有序集合</span></span><br><span class="line">列表：可以重复，有序，element</span><br><span class="line">有序集合：无重复元素，有序，element+score</span><br></pre></td></tr></table></figure>

<h3 id="6-2-API使用"><a href="#6-2-API使用" class="headerlink" title="6.2 API使用"></a>6.2 API使用</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">zadd key score element <span class="comment">#score可以重复，可以多个同时添加，element不能重复 o(logN) </span></span><br><span class="line"></span><br><span class="line">zrem key element <span class="comment">#删除元素，可以多个同时删除 o(1)</span></span><br><span class="line"></span><br><span class="line">zscore key element <span class="comment">#获取元素的分数 o(1)</span></span><br><span class="line"></span><br><span class="line">zincrby key increScore element <span class="comment">#增加或减少元素的分数  o(1)</span></span><br><span class="line"></span><br><span class="line">zcard key <span class="comment">#返回元素总个数 o(1)</span></span><br><span class="line"></span><br><span class="line">zrank key element <span class="comment">#返回element元素的排名（从小到大排）</span></span><br><span class="line"></span><br><span class="line">zrange key <span class="number">0</span> <span class="number">-1</span> <span class="comment">#返回排名，不带分数  o(log(n)+m) n是元素个数，m是要获取的值</span></span><br><span class="line">zrange player:rank <span class="number">0</span> <span class="number">-1</span> withscores <span class="comment">#返回排名，带分数</span></span><br><span class="line"></span><br><span class="line">zrangebyscore key minScore maxScore <span class="comment">#返回指定分数范围内的升序元素 o(log(n)+m) n是元素个数，m是要获取的值</span></span><br><span class="line">zrangebyscore user:<span class="number">1</span>:ranking <span class="number">90</span> <span class="number">210</span> withscores <span class="comment">#获取90分到210分的元素</span></span><br><span class="line"></span><br><span class="line">zcount key minScore maxScore <span class="comment">#返回有序集合内在指定分数范围内的个数 o(log(n)+m)</span></span><br><span class="line"></span><br><span class="line">zremrangebyrank key start end <span class="comment">#删除指定排名内的升序元素 o(log(n)+m)</span></span><br><span class="line">zremrangebyrank user:<span class="number">1</span>:rangking <span class="number">1</span> <span class="number">2</span> <span class="comment">#删除升序排名中1到2的元素</span></span><br><span class="line">        </span><br><span class="line">zremrangebyscore key minScore maxScore <span class="comment">#删除指定分数内的升序元素 o(log(n)+m)</span></span><br><span class="line">zremrangebyscore user:<span class="number">1</span>:ranking <span class="number">90</span> <span class="number">210</span> <span class="comment">#删除分数90到210之间的元素</span></span><br></pre></td></tr></table></figure>

<h3 id="6-3-实战"><a href="#6-3-实战" class="headerlink" title="6.3 实战"></a>6.3 实战</h3><p>排行榜：音乐排行榜，销售榜，关注榜，游戏排行榜</p>
<h3 id="6-4-其他操作"><a href="#6-4-其他操作" class="headerlink" title="6.4 其他操作"></a>6.4 其他操作</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">zrevrank <span class="comment">#从高到低排序</span></span><br><span class="line">zrevrange <span class="comment">#从高到低排序取一定范围</span></span><br><span class="line">zrevrangebyscore <span class="comment">#返回指定分数范围内的降序元素</span></span><br><span class="line">zinterstore <span class="comment">#对两个有序集合交集</span></span><br><span class="line">zunionstore <span class="comment">#对两个有序集合求并集</span></span><br></pre></td></tr></table></figure>

<h3 id="6-5-总结"><a href="#6-5-总结" class="headerlink" title="6.5 总结"></a>6.5 总结</h3><table>
<thead>
<tr>
<th>操作类型</th>
<th>命令</th>
</tr>
</thead>
<tbody><tr>
<td>基本操作</td>
<td>zadd/  zrem/  zcard/  zincrby/  zscore</td>
</tr>
<tr>
<td>范围操作</td>
<td>zrange/  zrangebyscore/  zcount/  zremrangebyrank</td>
</tr>
<tr>
<td>集合操作</td>
<td>zunionstore/  zinterstore</td>
</tr>
</tbody></table>
</section>
    <!-- Tags START -->
    
    <!-- Tags END -->
    <!-- NAV START -->
    
  <div class="nav-container">
    <!-- reverse left and right to put prev and next in a more logic postition -->
    
      <a class="nav-left" href="/db/MySQL%E7%B3%BB%E5%88%97/11-MySQL%E7%B3%BB%E5%88%97%E4%B9%8B-%E8%AF%BB%E5%86%99%E5%88%86%E7%A6%BB%E6%9E%B6%E6%9E%84-Atlas/">
        <span class="nav-arrow">← </span>
        
          db/MySQL系列/11-MySQL系列之-读写分离架构-Atlas
        
      </a>
    
    
      <a class="nav-right" href="/db/Redis%E7%B3%BB%E5%88%97/02-Redis%E7%B3%BB%E5%88%97%E4%B9%8B-%E5%AE%A2%E6%88%B7%E7%AB%AF%E4%BD%BF%E7%94%A8/">
        
          db/Redis系列/02-Redis系列之-客户端使用
        
        <span class="nav-arrow"> →</span>
      </a>
    
  </div>

    <!-- NAV END -->
    <!-- 打赏 START -->
    
      <div class="money-like">
        <div class="reward-btn">
          赏
          <span class="money-code">
            <span class="alipay-code">
              <div class="code-image"></div>
              <b>使用支付宝打赏</b>
            </span>
            <span class="wechat-code">
              <div class="code-image"></div>
              <b>使用微信打赏</b>
            </span>
          </span>
        </div>
        <p class="notice">点击上方按钮,请我喝杯咖啡！</p>
      </div>
    
    <!-- 打赏 END -->
    <!-- 二维码 START -->
    
      <div class="qrcode">
        <canvas id="share-qrcode"></canvas>
        <p class="notice">扫描二维码，分享此文章</p>
      </div>
    
    <!-- 二维码 END -->
    
      <!-- Gitment START -->
      <div id="comments"></div>
      <!-- Gitment END -->
    
  </article>
  <!-- Article END -->
  <!-- Catalog START -->
  
    <aside class="catalog-container">
  <div class="toc-main">
  <!-- 不蒜子统计 -->
    <strong class="toc-title">目录</strong>
    
      <ol class="toc-nav"><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#一-通用命令"><span class="toc-nav-text">一 通用命令</span></a><ol class="toc-nav-child"><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#1-1-通用命令"><span class="toc-nav-text">1.1 通用命令</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#1-2-数据结构和内部编码"><span class="toc-nav-text">1.2 数据结构和内部编码</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#1-3-单线程架构"><span class="toc-nav-text">1.3 单线程架构</span></a><ol class="toc-nav-child"><li class="toc-nav-item toc-nav-level-4"><a class="toc-nav-link" href="#1-3-1-单线程架构，"><span class="toc-nav-text">1.3.1 单线程架构，</span></a></li><li class="toc-nav-item toc-nav-level-4"><a class="toc-nav-link" href="#1-3-2-单线程为什么这么快"><span class="toc-nav-text">1.3.2 单线程为什么这么快</span></a></li><li class="toc-nav-item toc-nav-level-4"><a class="toc-nav-link" href="#1-3-3-注意"><span class="toc-nav-text">1.3.3 注意</span></a></li></ol></li></ol></li><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#二-字符串类型"><span class="toc-nav-text">二 字符串类型</span></a><ol class="toc-nav-child"><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#2-1-字符串键值结构"><span class="toc-nav-text">2.1 字符串键值结构</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#2-2-常用命令"><span class="toc-nav-text">2.2 常用命令</span></a></li></ol></li><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#三-哈希类型"><span class="toc-nav-text">三 哈希类型</span></a><ol class="toc-nav-child"><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#3-2-重要api"><span class="toc-nav-text">3.2 重要api</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#3-3-hash-vs-string"><span class="toc-nav-text">3.3 hash vs string</span></a><ol class="toc-nav-child"><li class="toc-nav-item toc-nav-level-4"><a class="toc-nav-link" href="#3-3-1相似的api"><span class="toc-nav-text">3.3.1相似的api</span></a></li><li class="toc-nav-item toc-nav-level-4"><a class="toc-nav-link" href="#3-3-2-缓存三种方案"><span class="toc-nav-text">3.3.2 缓存三种方案</span></a></li></ol></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#3-4-其他操作"><span class="toc-nav-text">3.4 其他操作</span></a></li></ol></li><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#四-列表类型"><span class="toc-nav-text">四 列表类型</span></a><ol class="toc-nav-child"><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#4-1-列表特点"><span class="toc-nav-text">4.1 列表特点</span></a><ol class="toc-nav-child"><li class="toc-nav-item toc-nav-level-4"><a class="toc-nav-link" href="#4-2-API操作"><span class="toc-nav-text">4.2 API操作</span></a><ol class="toc-nav-child"><li class="toc-nav-item toc-nav-level-5"><a class="toc-nav-link" href="#4-2-1-插入操作"><span class="toc-nav-text">4.2.1 插入操作</span></a></li><li class="toc-nav-item toc-nav-level-5"><a class="toc-nav-link" href="#4-2-2-删除操作"><span class="toc-nav-text">4.2.2 删除操作</span></a></li></ol></li><li class="toc-nav-item toc-nav-level-4"><a class="toc-nav-link" href="#4-2-3-查询操作"><span class="toc-nav-text">4.2.3 查询操作</span></a></li><li class="toc-nav-item toc-nav-level-4"><a class="toc-nav-link" href="#4-2-3-修改操作"><span class="toc-nav-text">4.2.3 修改操作</span></a></li></ol></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#4-3-实战"><span class="toc-nav-text">4.3 实战</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#4-4-其他操作"><span class="toc-nav-text">4.4 其他操作</span></a></li></ol></li><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#五-集合类型"><span class="toc-nav-text">五 集合类型</span></a><ol class="toc-nav-child"><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#5-1-特点"><span class="toc-nav-text">5.1 特点</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#5-2-API操作"><span class="toc-nav-text">5.2 API操作</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#5-3-实战"><span class="toc-nav-text">5.3 实战</span></a><ol class="toc-nav-child"><li class="toc-nav-item toc-nav-level-4"><a class="toc-nav-link" href="#5-4-总结"><span class="toc-nav-text">5.4 总结</span></a></li></ol></li></ol></li><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#六-有序集合类型"><span class="toc-nav-text">六 有序集合类型</span></a><ol class="toc-nav-child"><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#6-1-特点"><span class="toc-nav-text">6.1 特点</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#6-2-API使用"><span class="toc-nav-text">6.2 API使用</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#6-3-实战"><span class="toc-nav-text">6.3 实战</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#6-4-其他操作"><span class="toc-nav-text">6.4 其他操作</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#6-5-总结"><span class="toc-nav-text">6.5 总结</span></a></li></ol></li></ol>
    
  </div>
</aside>
  
  <!-- Catalog END -->
</main>

<script>
  (function () {
    var url = 'http://www.liuqingzheng.top/db/Redis系列/01-Redis系列之-API的使用/';
    var banner = ''
    if (banner !== '' && banner !== 'undefined' && banner !== 'null') {
      $('#article-banner').css({
        'background-image': 'url(' + banner + ')'
      })
    } else {
      $('#article-banner').geopattern(url)
    }
    $('.header').removeClass('fixed-header')

    // error image
    $(".markdown-content img").on('error', function() {
      $(this).attr('src', 'http://file.muyutech.com/error-img.png')
      $(this).css({
        'cursor': 'default'
      })
    })

    // zoom image
    $(".markdown-content img").on('click', function() {
      var src = $(this).attr('src')
      if (src !== 'http://file.muyutech.com/error-img.png') {
        var imageW = $(this).width()
        var imageH = $(this).height()

        var zoom = ($(window).width() * 0.95 / imageW).toFixed(2)
        zoom = zoom < 1 ? 1 : zoom
        zoom = zoom > 2 ? 2 : zoom
        var transY = (($(window).height() - imageH) / 2).toFixed(2)

        $('body').append('<div class="image-view-wrap"><div class="image-view-inner"><img src="'+ src +'" /></div></div>')
        $('.image-view-wrap').addClass('wrap-active')
        $('.image-view-wrap img').css({
          'width': `${imageW}`,
          'transform': `translate3d(0, ${transY}px, 0) scale3d(${zoom}, ${zoom}, 1)`
        })
        $('html').css('overflow', 'hidden')

        $('.image-view-wrap').on('click', function() {
          $(this).remove()
          $('html').attr('style', '')
        })
      }
    })
  })();
</script>


  <script>
    var qr = new QRious({
      element: document.getElementById('share-qrcode'),
      value: document.location.href
    });
  </script>



  <script>
    var gitmentConfig = "liuqingzheng";
    if (gitmentConfig !== 'undefined') {
      var gitment = new Gitment({
        id: "db/Redis系列/01-Redis系列之-API的使用",
        owner: "liuqingzheng",
        repo: "FuckBlog",
        oauth: {
          client_id: "32a4076431cf39d0ecea",
          client_secret: "94484bd79b3346a949acb2fda3c8a76ce16990c6"
        },
        theme: {
          render(state, instance) {
            const container = document.createElement('div')
            container.lang = "en-US"
            container.className = 'gitment-container gitment-root-container'
            container.appendChild(instance.renderHeader(state, instance))
            container.appendChild(instance.renderEditor(state, instance))
            container.appendChild(instance.renderComments(state, instance))
            container.appendChild(instance.renderFooter(state, instance))
            return container;
          }
        }
      })
      gitment.render(document.getElementById('comments'))
    }
  </script>




    <div class="scroll-top">
  <span class="arrow-icon"></span>
</div>
    <footer class="app-footer">
<!-- 不蒜子统计 -->
<span id="busuanzi_container_site_pv">
     本站总访问量<span id="busuanzi_value_site_pv"></span>次
</span>
<span class="post-meta-divider">|</span>
<span id="busuanzi_container_site_uv" style='display:none'>
     本站访客数<span id="busuanzi_value_site_uv"></span>人
</span>
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>



  <p class="copyright">
    &copy; 2021 | Proudly powered by <a href="https://www.cnblogs.com/xiaoyuanqujing" target="_blank">小猿取经</a>
    <br>
    Theme by <a href="https://www.cnblogs.com/xiaoyuanqujing" target="_blank" rel="noopener">小猿取经</a>
  </p>
</footer>

<script>
  function async(u, c) {
    var d = document, t = 'script',
      o = d.createElement(t),
      s = d.getElementsByTagName(t)[0];
    o.src = u;
    if (c) { o.addEventListener('load', function (e) { c(null, e); }, false); }
    s.parentNode.insertBefore(o, s);
  }
</script>
<script>
  async("//cdnjs.cloudflare.com/ajax/libs/fastclick/1.0.6/fastclick.min.js", function(){
    FastClick.attach(document.body);
  })
</script>

<script>
  var hasLine = 'true';
  async("//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js", function(){
    $('figure pre').each(function(i, block) {
      var figure = $(this).parents('figure');
      if (hasLine === 'false') {
        figure.find('.gutter').hide();
      }
      var lang = figure.attr('class').split(' ')[1] || 'code';
      var codeHtml = $(this).html();
      var codeTag = document.createElement('code');
      codeTag.className = lang;
      codeTag.innerHTML = codeHtml;
      $(this).attr('class', '').empty().html(codeTag);
      figure.attr('data-lang', lang.toUpperCase());
      hljs.highlightBlock(block);
    });
  })
</script>





<!-- Baidu Tongji -->

<script>
    var _baId = 'c5fd96eee1193585be191f318c3fa725';
    // Originial
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?" + _baId;
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
</script>


<script src="/js/script.js"></script>


<script src="/js/search.js"></script>


<script src="/js/load.js"></script>



  <span class="local-search local-search-google local-search-plugin" style="right: 50px;top: 70px;;position:absolute;z-index:2;">
      <input type="search" placeholder="站内搜索" id="local-search-input" class="local-search-input-cls" style="">
      <div id="local-search-result" class="local-search-result-cls"></div>
  </span>


  </body>
</html>